// pages/W_OrderList/index.js
var app = getApp()
var Keys = require('../../assets/data/keys.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    TabTypeArray: ['已取消', '待付款', '待收货', '待确认', '已完成'],
    Butten1TextArray: ['', '取消', '查看物流', '', ''],
    Butten2TextArray: ['再次购买', '付款', '确认收货', '确认安装', '评价'],
    TabTypeIndex: 0,//当前订单分类的编号
    TabIndexDataList: [],//当前订单分类的列表数据
    ScrollTopView: 'scroll_top_view',//切换分类时将ScrollView滑动至顶层
    datas:"",
    O_ID:"",

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      this.setData({
        O_ID : options.O_ID,
      })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.reqNetListData('已取消')
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },


	/**
 * 切换订单分类
 */
  btnEventChangeTab: function (e) {
    // console.log(this.data.ScrollTopView);

    this.setData({
      TabTypeIndex: e.currentTarget.dataset.index,
      ScrollTopView: this.data.ScrollTopView,
    })

    this.reqNetListData(this.data.TabTypeArray[e.currentTarget.dataset.index]);
  },

	/**
	 * ScrollView下拉刷新
	 */
  bindEventScrollViewUpdate: function () {
    // this.reqNetListData('全部')
  },

	/**
	 * 请求列表数据
	 */
  reqNetListData: function (listType) {
    console.log("输出");
    wx.showNavigationBarLoading()
    var _this = this;
    console.log(listType)
    wx.request({
			url: "https://www.chnode.xyz/api/Order_State.ashx?",
      data: {
        DataType: "OrderDetail",
        Token: getApp().data.Token,
        O_ID: _this.data.O_ID,
        // page: 1,
      },
      success: function (res) {
        console.log("vvvvvv");
        console.log(res.data)
        if (res.data.type == "datas") {
          _this.setData({
            TabIndexDataList: res.data.datas.OrderSub,
            datas: res.data.datas,
          })
        } else {
          _this.setData({
            TabIndexDataList: "",
          })
        }
      },
      complete: function () { wx.hideNavigationBarLoading() }
    })
  },

  test: function (e) {
    console.log(e)
  },

  ClickedLeft: function (e) {
    var _this = this;
    console.log(_this.data.TabTypeIndex);
    console.log("left");
    console.log(e.currentTarget.dataset.oid);
    // console.log(_this.data.TabTypeArray[_this.data.TabTypeIndex]);
    if (_this.data.TabTypeIndex == 1) {
      console.log("取消订单");

      wx.request({
				url: 'https://www.chnode.xyz/api/Order_State.ashx?',
        data: {
          DataType: "OrderCancel",
          Token: getApp().data.Token,
          O_ID: e.currentTarget.dataset.oid,
          // page: 1,
        },
        success: function (res) {
          console.log(res);
          _this.reqNetListData(_this.data.TabTypeArray[_this.data.TabTypeIndex]);
        },
      })


    }
  },

  ClickedRight: function (e) {
    var _this = this;
    console.log(_this.data.TabTypeIndex);
    console.log("right");
    if (_this.data.TabTypeIndex == 2) {
      console.log("确认收获");

      wx.request({
				url: 'https://www.chnode.xyz/api/Order_State.ashx?',
        data: {
          DataType: "OrderEnter",
          Token: getApp().data.Token,
          O_ID: e.currentTarget.dataset.oid,
          // page: 1,
        },
        success: function (res) {
          console.log(res);
          _this.reqNetListData(_this.data.TabTypeArray[_this.data.TabTypeIndex]);
        },
      })


    }

  },

  itemClicked: function (e) {
    var _this = this;
    console.log(e.currentTarget.dataset.index);
    console.log("点击");
    console.log(_this.data.TabIndexDataList[e.currentTarget.dataset.index].O_ID);
    wx.navigateTo({
      url: '../Fl_DingdanDetail/index?O_ID=' + _this.data.TabIndexDataList[e.currentTarget.dataset.index].O_ID,
    })
  },

  fuzhiClicked:function(){
    var _this = this;
    console.log(_this.data.datas.C_Code);
    console.log("复制");
    wx.setClipboardData({
      data: _this.data.datas.C_Code,
      success: function (res) {
        wx.getClipboardData({
          success: function (res) {
            console.log(res.data) // data

            wx.showToast({
              title: '复制成功',
              icon: 'success',
             
            })

          }
        })
      }
    })
  },


  fuzhiClicked1: function () {
    var _this = this;
    console.log(_this.data.datas.O_LogisticsNumber);
    console.log("复制");
    wx.setClipboardData({
      data: _this.data.datas.O_LogisticsNumber,
      success: function (res) {
        wx.getClipboardData({
          success: function (res) {
            console.log(res.data) // data

            wx.showToast({
              title: '复制成功',
              icon: 'success',

            })

          }
        })
      }
    })
  }
})